<?php
/**
 * Created by PhpStorm.
 * User: Duck
 * Create time: 2016/12/21 9:56
 */

namespace D\Controller;
use Common\Controller\BaseController;

class RoleChangeController extends BaseController{
   public function show(){
       $arr=array();
       $rol=M('roles')->field('role_id,role_name')->select();
       $arr['tea']=M('teachers')->field('teacher_id,tname,role_id')->select();
       foreach($arr['tea'] as $k=>$v){
           $arr['tea'][$k]['roles']=$rol;
       }
       $arr['stu']=M('students')->field('student_id,sname,class,role_id')->select();
       foreach($arr['stu'] as $k=>$v){
           $arr['stu'][$k]['roles']=$rol;
       }
        $this->assign('arr',$arr);
       $this->display();
   }
   public function savet(){
       if(D('teachers')->create()){
           if(D('teachers')->save()){
               $res='保存成功';
           }else{
               $res='保存失败';
           }
       }else{
           $res='数据错误';
       }
       $this->ajaxReturn($res);
   }
    public function saves(){
        if(D('students')->create()){
            if(D('students')->save()){
                $res='保存成功';
            }else{
                $res='保存失败';
            }
        }else{
            $res='数据错误';
        }
        $this->ajaxReturn($res);
    }
}